package com.example.myapplication

import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.WindowManager
import com.example.total.R
import com.example.total.databinding.ChoosePhotoLayoutBinding


class ChoosePhotoDialog(activity: Activity) : Dialog(activity, R.style.myDialog){
    private var camera:()->Unit = {}
    private var photo:()->Unit = {}
    private var binding: ChoosePhotoLayoutBinding
    init {
        val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        binding = ChoosePhotoLayoutBinding.inflate(inflater)
        setContentView(binding.root)
        window?.run {
            setGravity(Gravity.BOTTOM)
            setWindowAnimations(R.style.dialog_Anim_fade)
            val params = attributes
            params.width = WindowManager.LayoutParams.MATCH_PARENT
            attributes = params
        }
        binding.camera.setOnClickListener {
            dismiss()
            camera()
        }
        binding.photo.setOnClickListener {
            dismiss()
            photo()
        }
    }
    fun setCamera(listen:()->Unit = {}):ChoosePhotoDialog{
        this.camera = listen
        return this
    }

    fun setPhoto(listen:()->Unit = {}):ChoosePhotoDialog{
        this.photo = listen
        return this
    }
}